package svgedit.gui.actions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import svgedit.gui.Frame;

/**
 * Class To handle File->New
 * 
 * @author SARJ
 * 
 */
public class NewAction extends AbstractAction
{

	private static final long serialVersionUID = 1L;

	/**
	 * Construct a new Listener for New
	 */
	public NewAction()
	{
		super("New");
	}

	/**
	 * Listens for the button to be pressed.
	 */
	@Override
	public void actionPerformed(ActionEvent arg0)
	{
		// display the save dialog and saves the result
		Frame f = Frame.getFrame();
		int res = f.displaySaveDialog();

		// if the file is at last modified, open file
		if (!f.getChangesMade())
			f.newFile();
		else
		{
			// if result is yes, save the file
			if (res == JOptionPane.YES_OPTION && f.getChangesMade())
			{
				f.saveFile(Frame.DIALOG_MODE_CHECK);
				f.newFile();
			}
			// else no, just create a new file without saving
			else if (res == JOptionPane.NO_OPTION)
			{
				f.newFile();

			}
			// cancel case, do nothing
		}
	}
}
